<!-- 初始化Dict -->
var _dictKit = _GetDictKit();

<!-- 页面js,请自行将js内容导出到js文件中 -->
$(document).ready(function () {
  new SMValidator("form");
    var _listUrl = _CTX_ + _PATH_ + '/list';
    var _batchDeteleUrl = _CTX_ + _PATH_ + '/batchDelete';
  laydate({
    elem: '#schrq', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
    event: 'focus' //响应事件。如果没有传入event，则按照默认的click
  });
    laydate({
        elem: '#shcStart', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
        event: 'focus' //响应事件。如果没有传入event，则按照默认的click
    });
    laydate({
        elem: '#shcEnd', //目标元素。由于laydate.js封装了一个轻量级的选择器引擎，因此elem还允许你传入class、tag但必须按照这种方式 '#id .class'
        event: 'focus' //响应事件。如果没有传入event，则按照默认的click
    });

    $('#table').bootstrapTable({
        url: _listUrl,
        method: 'get',
        queryParams: function (params) {
            //每次查询时传入后台的查询条件
            var temp={
                pageSize: params.limit,   //页面大小
                pageNumber: params.pageNumber,  //页码
                jsdId:$("#s-jsdId").val(),
                yfk:$("#s-isFk").val(),
                s_shcStart:$("#shcStart").val(),
                s_shcEnd:$("#shcEnd").val()
            };
            return temp
        },
        pagination: true,
        pageNumber: 1,
        pageSize: 20,
        pageList: [20, 50, 100],
        clickToSelect: true,
        search: false,
        searchOnEnterKey: true,
        showRefresh: false,
        toolbar: '#toolbar',
        columns: [{
            checkbox: true
        }, {
            field: 'jsdId',
            title: '结算单号'
        }, {
            field: 'ddze',
            title: '交易总额'
        }, {
            field: 'jsje',
            title: '结算金额'
        }, {
            field: 'tzje',
            title: '调账金额'
        }, {
            field: 'yfje',
            title: '应付金额'
        }, {
            field: 'yjfje',
            title: '已付金额'
        }, {
            field: 'schrq',
            title: '生成日期'
        }, {
          field: '',
          title: '操作',
          formatter: function (value, row, index, field) {
            return '<div class="hidden-sm hidden-xs action-buttons">'
                + '<a class="green" href="javascript:viewData(\'' + row + '\')">'
                + '查看'
                + '</a>'
        + '</div>'
          }
        }]
    });

    $("#btnSearch").click(function () {
        $('#table').bootstrapTable("refresh");
    });

    $("#btnReset").click(function () {
        $("#searchForm").find("input,textarea,select").each(function () {
            $(this).val("");
        });
        $("#allFk").attr("selected",true);
        $('#table').bootstrapTable("refresh");
    });


    $('#btnAdd').click(function () {
        jsdxqDialog.show({}, {
            "title": "新增结算单",
            "type": "add",
            "callback": function () {
                $('#table').bootstrapTable("refresh");
            }
        });
    });

    $('#btnEdit').click(function () {
        var selections = $('#table').bootstrapTable('getSelections');
        if (selections && selections.length == 1) {
            jsdxqDialog.show(selections[0], {
                "title": "编辑结算单",
                "type": "edit",
                "callback": function () {
                    $('#table').bootstrapTable("refresh");
                }
            });
        }else{
            layer.msg("只能选择一个");
        }
    });


    window.viewData = function (row) {
        $('#table').bootstrapTable("refresh");
        var selections = $('#table').bootstrapTable('getSelections');
        if (selections && selections.length >0) {
            jsdxqDialog.show(selections[0], {
                "title": "查看结算单",
                "type": "view",
                "callback": function () {
                    $('#table').bootstrapTable("refresh");
                }
            });
        }
    };

    $('#btnDelete').click(function () {
        var selections = $('#table').bootstrapTable('getSelections');
        if (selections && selections.length >0) {
            var pkArray = [];
            for(var i in selections){
                pkArray.push(selections[i].uuid);
            }

            //询问框

            layer.confirm('确定要删除？', {
                btn: ['确定','取消'] //按钮
            }, function(){
                $.ajax({
                    url: _batchDeteleUrl,
                    type: 'POST',
                    data: $.param({"uuids": pkArray}, true),
                    cache: false,
                    dataType: 'json',
                    success: function (ret) {
                        if (ret.state == 'ok') {
                           layer.msg("删除成功");
                            $('#table').bootstrapTable('refresh');
                        } else {
                            layer.msg(ret.msg);
                        }
                    }
                });
            }, function(){
                layer.close();
            });

        }else{
            layer.msg("请选择要删除的数据");
        }
    });

    $('#table').bootstrapTable("resetView", {height: calcSuitableHeight($('#table'))});
    $(window).bind('resize', function () {
        $('#table').bootstrapTable("resetView", {height: calcSuitableHeight($('#table'))});
    });

})